
using TomShane.Neoforce.Controls;
using Microsoft.Xna.Framework;
using System.Net;
namespace GUI
{
sealed class SelectForm : Window
{
public Button button1;
public TextBox IP;
public TextBox Port;
public Label label1;
public Label label2;
    public CheckBox inet;
public SelectForm(Manager manager)
 : base(manager)
{
button1 = new Button(manager);
this.button1.Text = "Connect";
button1.Init();
button1.Left = 98;
button1.Top = 140;
button1.Width = 75;
button1.Height = 23;
button1.Parent = this;

IP = new TextBox(manager);
string strHostName = Dns.GetHostName();
IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
   
IPAddress[] addr = Dns.GetHostAddresses(strHostName);
string ipadr = "";
for (int i = 0; i < addr.Length; i++)
{
    if (addr[i].AddressFamily==System.Net.Sockets.AddressFamily.InterNetwork)
    {
        ipadr = addr[i].ToString();
        break;
    }
}   
this.IP.Text =  ipadr;
IP.Init();
IP.Left = 12;
IP.Top = 28;
IP.Width = 100;
IP.Height = 20;
IP.Parent = this;

Port = new TextBox(manager);
this.Port.Text = "7777";
Port.Init();
Port.Left = 13;
Port.Top = 88;
Port.Width = 100;
Port.Height = 20;
Port.Parent = this;

label1 = new Label(manager);
this.label1.Text = "IP";
label1.Init();
label1.Left = 13;
label1.Top = 9;
label1.Width = 17;
label1.Height = 13;
label1.Parent = this;

label2 = new Label(manager);
this.label2.Text = "Port";
label2.Init();
label2.Left = 12;
label2.Top = 69;
label2.Width = 26;
label2.Height = 13;
label2.Parent = this;


inet = new CheckBox(manager);
inet.Text = "goder.dyndns.info";
inet.Init();
inet.Left = 140;
inet.Top = 28;
inet.Width = 110;
inet.Height = 17;
inet.Name = "inet";
inet.Parent = this;

inet.CheckedChanged += new EventHandler(inet_CheckedChanged);


this.Width = 279;
this.Height = 200;
this.Text = "ServerSelekt";
this.Left = 0;
this.Top = 0;
}

void inet_CheckedChanged(object sender, EventArgs e)
{
    if (inet.Checked)
    {
        
        IPHostEntry ipEntry = Dns.GetHostEntry(inet.Text);
        IPAddress[] addr = Dns.GetHostAddresses(inet.Text);
        string ipadr = "";
        for (int i = 0; i < addr.Length; i++)
        {
            if (addr[i].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
            {
                ipadr = addr[i].ToString();
                break;
            }
        }   
        this.IP.Text = ipadr;
    }
    else
    {
        string strHostName = Dns.GetHostName();
        IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
        IPAddress[] addr = Dns.GetHostAddresses(strHostName);
        string ipadr = "";
        for (int i = 0; i < addr.Length; i++)
        {
            if (addr[i].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
            {
                ipadr = addr[i].ToString();
                break;
            }
        }   
        this.IP.Text = ipadr;
    }
}
}
}
